
Power analysis for conjoint based on Schuessler/Freitag 2020

```{r}
# if(!require(devtools)) install.packages("devtools") 
# library(devtools) 
# devtools :: install_github("m-freitag/cjpowR")
```

```{r}
library(cjpowR) 
```

```{r}
effect_sizes <- seq(0.005, 0.1, by=0.001)
power_out_3lvl <- numeric(length(effect_sizes))
for(i in 1:length(effect_sizes)) {
  power_out_3lvl[i] <- cjpowr_amce(amce = effect_sizes[i], levels = 3, alpha=0.05, n = 2785*2*3)[1]
}

power_out_2lvl <- numeric(length(effect_sizes))
for(i in 1:length(effect_sizes)) {
  power_out_2lvl[i] <- cjpowr_amce(amce = effect_sizes[i], levels = 2, alpha=0.05, n = 2785*2*3)[1]
}
```

```{r}
pdf("output/output_figures_appendix/figure_power_based_on_schuessler_freitag.pdf", height = 5, width = 7)
  plot(effect_sizes, power_out_2lvl, pch="", las=1, bty="n", xlab="AMCE size", ylab="Power", axes=F, xlim=c(0,0.1))
  axis(1, at=c(0, 0.02,0.04,0.06, 0.08, 0.1))
  axis(2, las=1)
  lines(effect_sizes, power_out_2lvl, col="#1b9e77")
  lines(effect_sizes, power_out_3lvl, col="#d95f02")
  text(0.017, 0.6, labels="two levels", pos=2, col="#1b9e77")
  text(0.02, 0.6, labels="three levels", pos=4, col="#d95f02")
  #abline(h=0.8, lty="dashed")
  #abline(h=0.9, lty="dashed")
  abline(h=0.95, lty="dashed")
dev.off()
```

```{r}
# Smallest significant effect for overall sample and immigration policy: Language Requirement - Basic language skills = -0.035
cjpowr_amce(amce = -0.035, levels = 3, alpha=0.05, n = 16560)
# power > 0.95

# Smallest significant effect for populism subsample and immigration policy: Withdrawal work permit - Never = -0.0315
cjpowr_amce(amce = -0.0315 , levels = 2, alpha=0.05, n = 8182)
# power > 0.8
```

